package cn.kailangtu.myapplication.data;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import java.util.List;

import cn.kailangtu.myapplication.view.AutoMeterView;


public class Tool {
    private static Tool instance;

    public static Tool getInstance() {
        if (instance == null) {
            instance = new Tool();
        }
        return instance;
    }
    public void 仪表盘(float 输入值, Integer dataView_id, Activity context) {
        View currentView = context.findViewById(dataView_id);
        if(currentView instanceof cn.kailangtu.myapplication.view.versionTwo.AutoMeterView) {
            ((cn.kailangtu.myapplication.view.versionTwo.AutoMeterView)currentView).setDegreeOffset(输入值);
        }
        else if(currentView instanceof cn.kailangtu.myapplication.view.AutoMeterView)
        {
            ((cn.kailangtu.myapplication.view.AutoMeterView)currentView).setDegreeOffset(输入值);
        }
    }
    public void 输入框(String 输入值, Integer dataView_id, Activity context) {
        TextView currentView = context.findViewById(dataView_id);
        currentView.setText( 输入值);
    }

    public void 选择器(int 当前值, Integer groupId, List<Integer> child,Activity context)
    {
        if(child != null && child.size() > 当前值) {
            RadioGroup rg = context.findViewById(groupId);
            rg.check(child.get(当前值));
        }
    }

    public void 输入框(int 输入值, int 隐藏, Integer dataView_id, Activity context) {
        TextView currentView = context.findViewById(dataView_id);
        currentView.setText("" + 输入值);
        if (隐藏 == 1) {
            currentView.setVisibility(View.VISIBLE);
        } else {
            currentView.setVisibility(View.GONE);
        }
    }

    public void 输入框(int 输入值, int 隐藏, int 背景色数据, int[] 颜色, Integer dataView_id, Activity context) {
        TextView currentView = context.findViewById(dataView_id);
        currentView.setText("" + 输入值);
        if (隐藏 == 1) {
            currentView.setVisibility(View.VISIBLE);
        } else {
            currentView.setVisibility(View.GONE);
        }
        currentView.setBackgroundResource(颜色[背景色数据]);
    }


    public void 标签(String 输入值, int 字体颜色, int 隐藏, int 背景色数据, int[] 颜色, Integer dataView_id, Activity context) {
        TextView currentView = context.findViewById(dataView_id);
        if (输入值 != null) {
            currentView.setText("" + 输入值);
        }
        if (隐藏 == 1) {
            currentView.setVisibility(View.VISIBLE);
        } else {
            currentView.setVisibility(View.GONE);
        }
        if (背景色数据 != 255) {
            currentView.setBackgroundResource(颜色[背景色数据]);
        }
        currentView.setTextColor(字体颜色);
    }

    public void 标签动画(String[] 显示, int 输入值, int 隐藏, Integer dataView_id, Activity context) {
        TextView currentView = context.findViewById(dataView_id);
        currentView.setText("" + 输入值);
        if (隐藏 == 1) {
            currentView.setVisibility(View.VISIBLE);
        } else {
            currentView.setVisibility(View.GONE);
        }
    }

    public void 标签动画(String[] 显示, int 输入值, @NonNull int[] 图片, int 隐藏, Integer dataView_id, Activity context) {
        TextView currentView = context.findViewById(dataView_id);
        currentView.setText("" + 输入值);
        currentView.setBackgroundResource(图片[输入值]);
        if (隐藏 == 1) {
            currentView.setVisibility(View.VISIBLE);
        } else {
            currentView.setVisibility(View.GONE);
        }
    }

    public void 标签动画(int 输入值, @NonNull int[] 图片, int 隐藏, Integer dataView_id, Activity context) {
        TextView currentView = context.findViewById(dataView_id);
        currentView.setText("" + 输入值);
        currentView.setBackgroundResource(图片[输入值]);
        if (隐藏 == 1) {
            currentView.setVisibility(View.VISIBLE);
        } else {
            currentView.setVisibility(View.GONE);
        }
    }

    public void 标签动画(boolean 数据, int 隐藏, Integer dataView_id, Activity context) {
        View currentView = context.findViewById(dataView_id);

        if (隐藏 == 1&&数据==true) {
            currentView.setVisibility(View.VISIBLE);
        } else {
            currentView.setVisibility(View.GONE);
        }
    }

    public void 标签动画(boolean 隐藏, Integer dataView_id, Activity context) {



        View currentView = context.findViewById(dataView_id);

        if(currentView.getTag() == null) {
            if (隐藏 == true) {
                currentView.setVisibility(View.VISIBLE);
            } else {
                currentView.setVisibility(View.INVISIBLE);
            }
        }
        else if(currentView.getTag().toString().equals("U1"))
        {
            if (隐藏 == true) {
                ((TextView)currentView).setText("故障");
                ((TextView)currentView).setTextColor(Color.RED);
            } else {
                ((TextView)currentView).setText("正常");
                ((TextView)currentView).setTextColor(Color.WHITE);
            }

        }
        else if(currentView.getTag().toString().equals("U0"))
        {
            if (隐藏 == true) {
                ((TextView)currentView).setText("是");
                ((TextView)currentView).setTextColor(Color.GREEN);
            } else {
                ((TextView)currentView).setText("正常");
                ((TextView)currentView).setTextColor(Color.WHITE);
            }

        }
        else
        {
            if (隐藏 == true) {
                currentView.setVisibility(View.VISIBLE);
            } else {
                currentView.setVisibility(View.INVISIBLE);
            }
        }
    }

    public void 密码框(int 输入值, int 当前位置, int 菜单, int 背景色数据, int[] 颜色, Integer dataView_id, Activity context) {
        TextView currentView = context.findViewById(dataView_id);
        if (当前位置 == 菜单) {
            currentView.setText("" + 输入值);
            currentView.setBackgroundResource(颜色[背景色数据]);
        } else {
            currentView.setText("*");
            currentView.setBackgroundResource(颜色[背景色数据 + 1]);
        }
    }


}
